﻿using System.Windows;

namespace SHomeWorkshop.LunarPresentation.Commands
{
    public partial class Command
    {
        public static void EditDocPageHeader()
        {
            if (Globals.selectedEditor == null)
            {
                MessageBox.Show("当前未打开任何文档，无法编辑文档页眉！",
                    Globals.appName, MessageBoxButton.OK, MessageBoxImage.Warning);
                return;
            }

            Dialogs.PageHeaderEditor pe = new Dialogs.PageHeaderEditor
                    (
                    Globals.selectedEditor.PageHeaderLeft,
                    Globals.selectedEditor.PageHeaderMiddle,
                    Globals.selectedEditor.PageHeaderRight
                    ) { Owner = Globals.MainWindow };

            if (pe.ShowDialog() == true)
            {
                ModifingItem mi = new ModifingItem();

                Action actPageHeaderLeft = new Action(null, -1, null, null,
                    Globals.selectedEditor.PageHeaderLeft, pe.PageHeaderLeft, ActionType.PageHeaderLeft);

                Globals.selectedEditor.PageHeaderLeft = pe.PageHeaderLeft;

                mi.Add(actPageHeaderLeft);

                Action actPageHeaderRight = new Action(null, -1, null, null,
                    Globals.selectedEditor.PageHeaderRight, pe.PageHeaderRight, ActionType.PageHeaderRight);

                Globals.selectedEditor.PageHeaderRight = pe.PageHeaderRight;

                mi.Add(actPageHeaderRight);

                Action actPageHeaderMiddle = new Action(null, -1, null, null,
                    Globals.selectedEditor.PageHeaderMiddle, pe.PageHeaderMiddle, ActionType.PageHeaderMiddle);

                Globals.selectedEditor.PageHeaderMiddle = pe.PageHeaderMiddle;

                mi.Add(actPageHeaderMiddle);

                Globals.selectedEditor.Do(mi);
                Globals.selectedEditor.IsModified = true;
            }
        }
    }
}
